package TCP;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;

public class Client {
    private Socket socket=null;
    public Client(String ip,int port) throws IOException {
        socket=new Socket(ip,port);
    }
    public void start() throws IOException {
        System.out.println("Client is Running...");
        Scanner scanner=new Scanner(System.in);
        try(OutputStream outputStream=socket.getOutputStream();
            InputStream inputStream=socket.getInputStream();
            PrintWriter printWriter=new PrintWriter(outputStream);
            Scanner scanNet=new Scanner(inputStream)){
            while(true){
                System.out.print("Enter:>");
                String request=scanner.next();
                printWriter.println(request);
                printWriter.flush();
                String response=scanNet.next();
                System.out.println(response);
            }
        }
    }
    public static void main(String[] args) throws IOException {
        Client client=new Client("127.0.0.1",9090);
        client.start();
    }
}
